import redis

def redis_cli(host='', port='', password='', key='', value='', ex=60):
    """
    操作redis
    :param host: redis IP
    :param port: redis port
    :param password: redis passwd
    :param key: redis key
    :param value: redis value
    :param ex: key的超时时间
    :return: 状态码 | value
    """
    conn = redis.Redis(host=host, port=port, password=password, encoding='utf-8')
    if value:
        try:
            conn.set(key,value,ex)
        except Exception as e:
            return 500
        else:
            return 200
    value = conn.get(key)
    return value

